class HPage:
    # 优化分页
    @staticmethod
    def get_page(paginator, page, around_page=1):
        # 获取当前页面
        current_page = page.number
        # 获取总页数
        total_page = paginator.num_pages
        # 左右是否显示 ...
        left_has_more = False
        right_has_more = False
        # 1, ... ,4 , 5, [6], 7, 8,..., 11
        # 1, ... , 5, 6, [7], 8,9, 10, 11
        # 1, 2, 3 , 4, [5], 6, 7, ..., 11
        # range(4, 7) 4, 5
        # range(5, 7) 5, 6
        left_start_index = current_page - around_page
        # left_end_index = current_page
        # range(1, 4) ==> 1, 2 , 3
        if current_page <= around_page + 3:
            left_pages = range(1, current_page)
        else:
            left_has_more = True
            left_pages = range(left_start_index, current_page)

        # 1, 2, 3 , 4, [5], 6, 7, ..., 11
        # range(6, 9)
        right_start_index = current_page + 1
        right_end_index = current_page + around_page + 1
        if current_page >= total_page - around_page - 2:
            right_pages = range(current_page + 1, total_page + 1)
        else:
            right_has_more = True
            right_pages = range(right_start_index, right_end_index)

        return {
            "current_page": current_page,
            "total_page": total_page,
            "left_has_more": left_has_more,
            "right_has_more": right_has_more,
            "left_pages": left_pages,
            "right_pages": right_pages,
        }